from sklearn.cluster import KMeans
import numpy as np
import matplotlib.pyplot as plt  
"""
initial cluster centers are:
C1 (4.6,3.1,1.5,0.2)
C2 (7.2,3.2,6,1.8)
C3 (6.7,3.1,5.6,2.4)

It takes 9 steps to converge.

Final cluster centers are:
C1 (5.00784,3.4098,1.49216,0.262745)
C2 (6.57705,2.97541,5.41311,1.9377)
C3 (5.78684,2.71579,4.17632,1.27105)

labels sequence is:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 1 2 1 2 2 2 1 1 2 2 2 2 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 

"""

X = []

for line in open("./data/k-means/Iris.txt", "r", encoding="utf-8"):
    data = list(map(float, line.strip().split()))
    X.append(data)

X = np.array(X)

cluster_centers = np.array([
    (4.6,3.1,1.5,0.2),
    (7.2,3.2,6,1.8),
    (6.7,3.1,5.6,2.4)
])

cluster_model = KMeans(n_clusters=3, init=cluster_centers, n_init=1)
cluster_model.fit(X)

print(cluster_model.cluster_centers_)

for lab in cluster_model.labels_:
    print(lab, end=" ")

